package com.lihang.rabbit1.config;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;

/**
 * 应用启动监听器
 */
@Component
public class AppStartupRunner implements ApplicationRunner {

    // 使用SLF4J Logger接口
    private static final Logger log = LoggerFactory.getLogger(AppStartupRunner.class);

    @Value("${server.port:8080}")
    private String serverPort;

    @Value("${springdoc.swagger-ui.path:/swagger-ui.html}")
    private String swaggerPath;

    @Override
    public void run(ApplicationArguments args) {
        String docUrl = "http://localhost:" + serverPort + swaggerPath;

        // 使用SLF4J记录应用启动信息
        log.info("\n----------------------------------------------------------\n" +
                "\t高仿小兔鲜电商系统后端启动成功！\n" +
                "\t本地访问: http://localhost:{}\n" +
                "\tOpenAPI文档: {}\n" +
                "----------------------------------------------------------",
                serverPort, docUrl);

        // 直接输出到控制台的ASCII艺术字
        String asciiArt = "\n" +
                " _____                    _____ _____ _____ \n" +
                "|     |___ ___ ___ ___ ___|  _  |  _  |     |\n" +
                "|  |  | . | -_|   |   |___|     |     |  |  |\n" +
                "|_____|  _|___|_|_|_|_|   |__|__|__|__|_____|\n" +
                "      |_|                                   \n";

        log.info(asciiArt);
        log.info("访问OpenAPI文档: {}", docUrl);
    }
}